package com.tjp.eight.base;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentTransaction;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.tjp.eight.R;
import com.tjp.eight.comment.AppManager;
import com.umeng.analytics.MobclickAgent;

import me.imid.swipebacklayout.lib.SwipeBackLayout;
import me.imid.swipebacklayout.lib.ViewDragHelper;
import me.imid.swipebacklayout.lib.app.SwipeBackActivity;

/**
 * Created by Administrator on 2017/2/20.
 */

public abstract class BaseActivitySwipe extends SwipeBackActivity {
    SwipeBackLayout swipeBackLayout;
    public RelativeLayout rlLeft;
    public RelativeLayout rl_head_nav;
    public RelativeLayout rlRight;
    public TextView tvTitle;
    public ImageView ivLeft;
    public ImageView ivRight;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        AppManager.getAppManager().AddActivity(this);
        setContentView(R.layout.acty_article_detail);
        initTitle();
        initTitleAll();
        setFragment();
        swipeBackLayout = getSwipeBackLayout();
        swipeBackLayout.setEdgeTrackingEnabled(ViewDragHelper.EDGE_LEFT);
    }

    void initTitle() {
        rlLeft = (RelativeLayout) findViewById(R.id.rl_head_left);
        rl_head_nav = (RelativeLayout) findViewById(R.id.rl_head_nav);
        rlRight = (RelativeLayout) findViewById(R.id.rl_head_right);
        tvTitle = (TextView) findViewById(R.id.tv_title);
        ivLeft = (ImageView) findViewById(R.id.iv_head_left);
        ivRight = (ImageView) findViewById(R.id.iv_head_right);
    }

    public abstract void setFragment();

    public abstract void initTitleAll();

    public void changeFragment(Fragment f) {
        changeFragment(f, false);
    }

    public void changeFragment(Fragment f, boolean isCanBack) {
        FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
        ft.replace(R.id.acty_article_detail_content, f);
        if (isCanBack)
            ft.addToBackStack(null);
        ft.commitAllowingStateLoss();
    }

    @Override
    public void onBackPressed() {
        AppManager.getAppManager().finishActivity(this);
    }

    @Override
    protected void onResume() {
        super.onResume();
        MobclickAgent.onResume(this);
    }

    @Override
    protected void onPause() {
        super.onPause();
        MobclickAgent.onResume(this);
    }
    public void finish() {
        super.finish();
        overridePendingTransition(R.anim.in_from_right, R.anim.out_from_right);
    }
}
